﻿using MediatR; 

namespace LogTestApp.Commands
{
    public class ExceptionPipelineBehavior<TResult, TResponse> : IPipelineBehavior<TResult, TResponse> where TResult : notnull
    {
        public async Task<TResponse> Handle(TResult request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
        {
            TResponse? response;
            try
            { 
                response = await next();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"发生了一个{ex.GetType().FullName}异常"); 
                throw;
            }
            return response;
        }
    }

}